home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_069 / blitlab / blitlab.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  5KB  |  182 lines

  1. /*
  2.  *   This is the main routine from BlitLab.
  3.  */
  4. #include "structures.h"
  5. /*
  6.  *   Here are all the globals we use.  (Yuck!  Globals!)
  7.  */
  8. struct Window *mywindow ;
  9. struct GfxBase *GfxBase ;
  10. struct IntuitionBase *IntuitionBase ;
  11. struct RastPort *myrp ;
  12. char strings[900] ;
  13. char *bufarr[MAXGADG] ;
  14. long gvals[MAXGADG] ;
  15. struct Gadget *gadgets[MAXGADG] ;
  16. char errorbuf[140] ;
  17. short *realbits ;
  18. struct blitregs blitregs ;
  19. int errortitle ;
  20. /*
  21.  *   Externals we use:
  22.  */
  23. extern int blitsafe() ;
  24. /*
  25.  *   Some statics to this module.
  26.  */
  27. static int updatethem ;
  28. /*
  29.  *   Errors go through here.  Currently, we write to the CLI window.
  30.  *   Later, we will write to the title bar of the window.
  31.  */
  32. error(s)
  33. char *s ;
  34. {
  35.    if (mywindow == NULL)
  36.       printf("blitlab: %s\n", s) ;
  37.    else {
  38.       SetWindowTitles(mywindow, s, -1L) ;
  39.       errortitle = 1 ;
  40.    }
  41.    if (*s == '!')
  42.       cleanup() ;
  43. }
  44. /*
  45.  *   This routine handles a gadget selection.
  46.  */
  47. handlegadget(gp)
  48. register struct Gadget *gp ;
  49. {
  50.    static int gocount = 0 ;
  51.  
  52.    if (errortitle == 1) {
  53.       SetWindowTitles(mywindow, BANNER, -1L) ;
  54.       errortitle = 0 ;
  55.    }
  56.    if (bufarr[gp->GadgetID] == NULL)
  57.    switch(gp->GadgetID) {
  58.       case GDGPNTREG:
  59.       case GDGCLRSET:
  60.       case GDGLINE:
  61.       case GDGDESC:
  62.       case GDGFCI:
  63.       case GDGIFE:
  64.       case GDGEFE:
  65.       case GDGUSEA:
  66.       case GDGUSEB:
  67.       case GDGUSEC:
  68.       case GDGUSED:
  69.          flipgadg(gp->GadgetID) ;
  70.          break ;
  71.       case GDGCALC:
  72.          parseall() ;
  73.          updatethem = 0 ;
  74.          if (!blitsafe()) {
  75.             error("Blit unsafe.") ;
  76.          }
  77.          break ;
  78.       case GDGSETUP:
  79.          setupline() ;
  80.          parseall() ;
  81.          break ;
  82.       case GDGGO:
  83.          gocount += 2 ;
  84.          parseall() ;
  85.          updatethem = 0 ;
  86.          if (!blitsafe()) {
  87.             if (gocount < 3)
  88.                error("Blit unsafe---hit again to override") ;
  89.             else {
  90.                doblit() ;
  91.                updatebits() ;
  92.             }
  93.          } else {
  94.             doblit() ;
  95.             updatebits() ;
  96.          }
  97.          break ;
  98.       default:
  99.          error("! bad value in gadget switch") ;
  100.          break ;
  101.    }
  102.    if (gocount > 0)
  103.       gocount-- ;
  104. }
  105. /*
  106.  *   The main routine, no arguments.  Sets things up, and then goes
  107.  *   through the standard Intuition message loop.
  108.  *
  109.  *   It may look like I'm setting message to NULL and checking it and
  110.  *   everything all over, but that is so I can introduce interruptibility
  111.  *   into some operations later, if I choose.
  112.  */
  113. main() {
  114.    struct IntuiMessage *message = NULL ;
  115.    int x, y ;
  116.    int mousemoved = 0 ;
  117.    int getouttahere = 0 ;
  118.    int selectdown = 0 ;
  119.    int bam ;
  120.    int ox, oy ;
  121.  
  122.    initialize() ;
  123.    while (1) {
  124.       mousemoved = 0 ;
  125.       bam = 0 ;
  126.       if (message == NULL)
  127.          WaitPort(mywindow->UserPort) ;
  128.       while (message || (message = 
  129.                        (struct IntuiMessage *)GetMsg(mywindow->UserPort))) {
  130.          x = message->MouseX ;
  131.          y = message->MouseY ;
  132.          if (message->Class == MOUSEMOVE) {
  133.             ReplyMsg(message) ;
  134.             message = NULL ;
  135.             mousemoved = 1 ;
  136.          } else {
  137.             if (message->Class == MOUSEBUTTONS) {
  138.                selectdown = (message->Code == SELECTDOWN) ;
  139.                bam = 1 ;
  140.             } else if (message->Class == GADGETDOWN || 
  141.                        message->Class == GADGETUP) {
  142.                updatethem = 1 ;
  143.                handlegadget((struct Gadget *)(message->IAddress)) ;
  144.             } else if (message->Class == CLOSEWINDOW) {
  145.                getouttahere = 1 ;
  146.             } else
  147.                error("! undefined message class") ;
  148.             ReplyMsg(message) ;
  149.             message = NULL ;
  150.          }
  151.       }
  152.       if (getouttahere)
  153.          break ;
  154.       if (updatethem) {
  155.          parseall() ;
  156.          updatethem = 0 ;
  157.       }
  158.       x = (x - HBITSTART) / 6 ;
  159.       y = (y - VBITSTART) / 3 ;
  160.       if (y < 32 && x < 96 && x >= 0 && y >= 0) {
  161.          if (gvals[GDGPNTREG]) {
  162.             if (bam) {
  163.                if (selectdown) {
  164.                   ox = x ;
  165.                   oy = y ;
  166.                } else {
  167.                   preg(ox, oy, x, y, (int)gvals[GDGCLRSET]) ;
  168.                }
  169.             }
  170.          } else {
  171.             if (selectdown)
  172.                pdot(x, y, (int)gvals[GDGCLRSET]) ;
  173.          }
  174.          if (message != NULL || (message = 
  175.                (struct IntuiMessage *)GetMsg(mywindow->UserPort))) ;
  176.          else
  177.             updatepos(x, y) ;
  178.       }      
  179.    }
  180.    cleanup() ;
  181. }
  182.